/**
 * 用户服务API
 */
import http from "./http";
import { PaginatedData, PaginationParams } from "../types/api";
import { User } from "../types/user";

/**
 * 用户登录参数
 */
export interface LoginParams {
  username: string;
  password: string;
  remember?: boolean;
}

/**
 * 登录响应
 */
export interface LoginResult {
  token: string;
  user: User;
}

/**
 * 用户服务
 */
const userService = {
  /**
   * 用户登录
   */
  login: (params: LoginParams) => {
    return http.post<LoginResult>("/auth/login", params);
  },

  /**
   * 获取当前用户信息
   */
  getCurrentUser: () => {
    return http.get<User>("/auth/me");
  },

  /**
   * 获取用户列表 /console/sys_user/search?keyword=万&page_size-30&page_num=1
   */
  getUsers: (params: PaginationParams) => {
    return http.get<PaginatedData<User>>("/console/sys_user/search", params);
  },

  /**
   * 获取用户详情
   */
  getUserById: (id: string) => {
    return http.get<User>(`/users/${id}`);
  },

  /**
   * 更新用户信息
   */
  updateUser: (id: string, data: Partial<User>) => {
    return http.put<User>(`/users/${id}`, data);
  },

  /**
   * 删除用户
   */
  deleteUser: (id: string) => {
    return http.delete<boolean>(`/users/${id}`);
  },
};

export default userService;
